<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="下级用户ID" prop="lowerChangeId" label-width="90px">
        <el-input
          v-model="queryParams.lowerChangeId"
          placeholder="请输入下级用户ID"
          clearable
        />
      </el-form-item>
      <el-form-item
        label="下级用户手机"
        prop="lowerChangePhone"
        label-width="100px"
      >
        <el-input
          v-model="queryParams.lowerChangePhone"
          placeholder="请输入下级用户手机号"
          clearable
        />
      </el-form-item>
      <el-form-item label="推荐人ID" prop="afterChangeId" label-width="70px">
        <el-input
          v-model="queryParams.afterChangeId"
          placeholder="请输入修改后推荐人ID"
          clearable
        />
      </el-form-item>
      <el-form-item
        label="推荐人手机"
        prop="afterChangePhone"
        label-width="90px"
      >
        <el-input
          v-model="queryParams.afterChangePhone"
          placeholder="请输入修改后推荐人手机号"
          clearable
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="changeTimeStart">
        <el-date-picker
          v-model="queryParams.changeTimeStart"
          type="date"
          placeholder="请选择开始时间"
          clearable
          :editable="false"
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="changeTimeEnd">
        <el-date-picker
          v-model="queryParams.changeTimeEnd"
          type="date"
          placeholder="请选择结束时间"
          clearable
          :editable="false"
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-alert
      title="注意：先在会员列表修改用户的关系链上级，再在这里修改，否则不生效！！"
      type="error"
    ></el-alert>

    <el-table :data="tableList" highlight-current-row>
      <el-table-column
        label="下级用户ID"
        align="center"
        prop="lowerChangeId"
        width="90"
      />
      <el-table-column
        label="下级用户信息"
        align="center"
        prop="juniorUserName"
      >
        <template slot-scope="scope">
          <div class="user-box">
            <el-image
              style="width: 50px; height: 50px; margin-right: 5px"
              :src="scope.row.lowerChangeHead"
            ></el-image>
            <div>
              <div>{{ scope.row.lowerChangeName }}</div>
              <div>{{ scope.row.lowerChangePhone }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="原推荐人ID"
        align="center"
        prop="beforeChangeId"
        width="90"
      />
      <el-table-column
        label="原推荐人信息"
        align="center"
        prop="formerUserName"
      >
        <template slot-scope="scope">
          <div class="user-box">
            <el-image
              style="width: 50px; height: 50px; margin-right: 5px"
              :src="scope.row.beforeChangeHead"
            ></el-image>
            <div>
              <div>{{ scope.row.beforeChangeName }}</div>
              <div>{{ scope.row.beforeChangePhone }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="修改后推荐人ID"
        align="center"
        prop="afterChangeId"
        width="120"
      />
      <el-table-column
        label="修改后推荐人信息"
        align="center"
        prop="updateUserName"
      >
        <template slot-scope="scope">
          <div class="user-box">
            <el-image
              style="width: 50px; height: 50px; margin-right: 5px"
              :src="scope.row.afterChangeHead"
            ></el-image>
            <div>
              <div>{{ scope.row.afterChangeName }}</div>
              <div>{{ scope.row.afterChangePhone }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="updateTime" />
    </el-table>

    <!-- total -->
    <pagination
      v-show="tableList.length > 0"
      :total="tableList.length"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { changeList } from "@/api/doubleCopy/teamManage";

export default {
  name: "Promote",
  data() {
    return {
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        juniorUserId: null,
        juniorPhone: null,
        referrerId: null,
        referrerPhone: null,
        startTime: null,
        endTime: null,
      },
      tableList: [],
    };
  },
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    // 查询推广变更列表
    getList() {
      this.loading = true;
      changeList(this.queryParams).then((response) => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>

<style lang="less" scoped>
.user-box {
  display: flex;
  justify-content: center;
}
</style>
